package com.icinfo.cloud.provider.common.crontask;

import com.icinfo.cloud.provider.punish.actscode.service.ICaseActsCodeErrInfoService;
import com.icinfo.cloud.provider.punish.common.datareport.service.impl.*;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 处罚行政行为码重新赋码定时任务
 * @author liyafeng
 * @date 2023/3/10
 */
@Configuration
@EnableScheduling
@Slf4j
@RestController
@RequestMapping("/dataReportTask")
public class CaseActCodeReSaveTask {
    private static final String CASE_ACTCODE_RESAVE_REDIS_KEY = "PUNISH:CASE_ACTCODE_RESAVE_REDIS_KEY";
    @Resource
    private ICaseActsCodeErrInfoService caseActsCodeErrInfoService;
    @Resource
    private RedisTemplate<String, String> redisTemplate;


    /**
     * 行政行为码定时重新赋码
     * @author liyafeng
     * @date 2023/3/10
      * @param
     * @return
     */
    //@Scheduled(cron = "0 20 1 * * ?")
    public void reSaveCaseActsCodeInfo() {
        //防止多台服务器重复执行（过期时间设置为10分钟，预防服务器时间不同步）
        if (!redisTemplate.opsForValue().setIfAbsent(CASE_ACTCODE_RESAVE_REDIS_KEY, CASE_ACTCODE_RESAVE_REDIS_KEY, 10, TimeUnit.MINUTES)) {
            log.info("--------当前服务器未拿到分布式锁，不执行逻辑----------");
            return;
        }
        caseActsCodeErrInfoService.reSaveCaseActsCodeInfo();
    }


}
